home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 49 / Amiga Format CD49 (2000-01-17)(Future Publishing)(GB)(Track 1 of 3)[!][issue 2000-02].iso / -serious- / misc / pdflib / bind / c / pdfclock.c < prev    next >
C/C++ Source or Header  |  1999-12-06  |  4KB  |  132 lines

  1. /*---------------------------------------------------------------------------*
  2.  |        PDFlib - A library for dynamically generating PDF files            |
  3.  +---------------------------------------------------------------------------+
  4.  |        Copyright (c) 1997-1999 Thomas Merz. All rights reserved.          |
  5.  +---------------------------------------------------------------------------+
  6.  |    This software is not in the public domain.  It is subject to the       |
  7.  |    "Aladdin Free Public License".  See the file license.txt for details.  |
  8.  |    This license grants you the right to use and redistribute PDFlib       |
  9.  |    under certain conditions. Among other things, the license requires     |
  10.  |    that the copyright notice and this notice be preserved on all copies.  |
  11.  |    This requirement extends to ports to other programming languages.      |
  12.  |                                                                           |
  13.  |    In short, you are allowed to develop and use PDFlib-based software     |
  14.  |    as long as you don't sell it. Commercial use of PDFlib requires a      |
  15.  |    commercial license which can be obtained from the author of PDFlib.    |
  16.  |    Contact information can be found in the accompanying PDFlib manual.    |
  17.  |    PDFlib is distributed with no warranty of any kind. Commercial users,  |
  18.  |    however, will receive warranty and support statements in writing.      |
  19.  *---------------------------------------------------------------------------*/
  20.  
  21. /* pdfclock.c
  22.  *
  23.  * A little PDFlib application to draw an analog clock.
  24.  *
  25.  */
  26.  
  27. #include <stdio.h>
  28. #include <time.h>
  29.  
  30. #include "pdflib.h"
  31.  
  32. #define RADIUS        200.0
  33. #define MARGIN        20.0
  34.  
  35. int
  36. main(int argc, char *argv[])
  37. {
  38.     PDF        *p;
  39.     float    alpha;
  40.     time_t    timer;
  41.     struct tm    ltime;
  42.     
  43.     p = PDF_new();
  44.  
  45.     if (PDF_open_file(p, "pdfclock_c.pdf") == -1) {
  46.     fprintf(stderr, "Error: cannot open PDF file pdfclock_c.pdf.\n");
  47.     exit(2);
  48.     }
  49.  
  50.     PDF_set_info(p, "Creator", "pdfclock.c");
  51.     PDF_set_info(p, "Author", "Thomas Merz");
  52.     PDF_set_info(p, "Title", "PDF clock (C)");
  53.  
  54.     PDF_begin_page(p, (unsigned int) (2 * (RADIUS + MARGIN)),
  55.               (unsigned int) (2 * (RADIUS + MARGIN)));
  56.     
  57.     PDF_translate(p, RADIUS + MARGIN, RADIUS + MARGIN);
  58.     PDF_setrgbcolor(p, 0.0, 0.0, 1.0);
  59.     PDF_save(p);
  60.  
  61.     /* minute strokes */
  62.     PDF_setlinewidth(p, 2.0);
  63.     for (alpha = 0; alpha < 360; alpha += 6)
  64.     {
  65.     PDF_rotate(p, 6.0);
  66.     PDF_moveto(p, RADIUS, 0.0);
  67.     PDF_lineto(p, (float) (RADIUS-MARGIN/3), 0.0);
  68.     PDF_stroke(p);
  69.     }
  70.  
  71.     PDF_restore(p);
  72.     PDF_save(p);
  73.  
  74.     /* 5 minute strokes */
  75.     PDF_setlinewidth(p, 3.0);
  76.     for (alpha = 0; alpha < 360; alpha += 30)
  77.     {
  78.     PDF_rotate(p, 30.0);
  79.     PDF_moveto(p, RADIUS, 0.0);
  80.     PDF_lineto(p, RADIUS-MARGIN, 0.0);
  81.     PDF_stroke(p);
  82.     }
  83.  
  84.     time(&timer);
  85.     ltime = *localtime(&timer);
  86.  
  87.     /* draw hour hand */
  88.     PDF_save(p);
  89.     PDF_rotate(p, 
  90.         (float)(-((ltime.tm_min/60.0) + ltime.tm_hour - 3.0) * 30.0));
  91.     PDF_moveto(p, -RADIUS/10, -RADIUS/20);
  92.     PDF_lineto(p, RADIUS/2, 0.0);
  93.     PDF_lineto(p, -RADIUS/10, RADIUS/20);
  94.     PDF_closepath(p);
  95.     PDF_fill(p);
  96.     PDF_restore(p);
  97.  
  98.     /* draw minute hand */
  99.     PDF_save(p);
  100.     PDF_rotate(p,
  101.         (float) (-((ltime.tm_sec/60.0) + ltime.tm_min - 15.0) * 6.0));
  102.     PDF_moveto(p, -RADIUS/10, -RADIUS/20);
  103.     PDF_lineto(p, RADIUS * 0.8, 0.0);
  104.     PDF_lineto(p, -RADIUS/10, RADIUS/20);
  105.     PDF_closepath(p);
  106.     PDF_fill(p);
  107.     PDF_restore(p);
  108.  
  109.     /* draw second hand */
  110.     PDF_setrgbcolor(p, 1.0, 0.0, 0.0);
  111.     PDF_setlinewidth(p, 2);
  112.     PDF_save(p);
  113.     PDF_rotate(p, (float) -((ltime.tm_sec - 15.0) * 6.0));
  114.     PDF_moveto(p, -RADIUS/5, 0.0);
  115.     PDF_lineto(p, RADIUS, 0.0);
  116.     PDF_stroke(p);
  117.     PDF_restore(p);
  118.  
  119.     /* draw little circle at center */
  120.     PDF_circle(p, 0, 0, (float) RADIUS/30);
  121.     PDF_fill(p);
  122.  
  123.     PDF_restore(p);
  124.  
  125.     PDF_end_page(p);
  126.  
  127.     PDF_close(p);
  128.     PDF_delete(p);
  129.  
  130.     exit(0);
  131. }
  132.